package net.fltx.taskmgr.entity;

import java.util.Objects;

/**
 * 进程信息对象
 */
public class ProcessEntity implements Comparable<ProcessEntity>{
    private int pid;
    private String name;
    private int parentId;
    private int memory;
    private int cpu;
    private String path;

    public ProcessEntity(){}
    public ProcessEntity(int pid, String name, int parentId, int memory, int cpu, String path) {
        this.pid = pid;
        this.name = name;
        this.parentId = parentId;
        this.memory = memory;
        this.cpu = cpu;
        this.path = path;
    }

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getParentId() {
        return parentId;
    }

    public void setParentId(int parentId) {
        this.parentId = parentId;
    }

    public int getMemory() {
        return memory;
    }

    public void setMemory(int memory) {
        this.memory = memory;
    }

    public int getCpu() {
        return cpu;
    }

    public void setCpu(int cpu) {
        this.cpu = cpu;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ProcessEntity that = (ProcessEntity) o;
        return pid == that.pid &&
                parentId == that.parentId &&
                name.equals(that.name) &&
                path.equals(that.path);
    }

    @Override
    public int hashCode() {
        return Objects.hash(pid, name, parentId, path);
    }

    @Override
    public String toString() {
        return "ProcessEntity{" +
                "pid=" + pid +
                ", name='" + name + '\'' +
                ", parentId=" + parentId +
                ", memory=" + memory +
                ", cpu=" + cpu +
                ", path='" + path + '\'' +
                '}';
    }

    @Override
    public int compareTo(ProcessEntity o) {
        if(this.parentId>o.getParentId()) return 1;
        else if (this.parentId==o.getParentId()) return 0;
        else return -1;
    }
}
